﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MPMovieCatalog.Settings.Sections;

namespace MPMovieCatalog.Settings
{
    public partial class SettingsForm : Form
    {
        private Dictionary<string, SettingsSection> m_sections = new Dictionary<string, SettingsSection>();

        private ConnectionSection m_connectionSection = new ConnectionSection();

        public SettingsForm()
        {
            InitializeComponent();

            AddSection(m_connectionSection);

            LoadSettings();
        }

        public void LoadSettings()
        {
            foreach (SettingsSection section in m_sections.Values)
            {
                section.LoadSettings();
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (treeView1.SelectedNode != null && treeView1.SelectedNode.Text != string.Empty)
            {
                SettingsSection section = m_sections[treeView1.SelectedNode.Text];
                panel.Controls.Clear();
                panel.Controls.Add(section);
            }
        }

        private void AddSection(SettingsSection section)
        {
            m_sections.Add(section.Text, section);
            treeView1.Nodes.Add(section.Text);
        }
    }
}
